<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #content {
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            right: 0px;
            bottom: 0px;
            cursor: pointer;
        }
    </style>
</head>

<body style="height: 2000px">
    <input type="button" value="开始运动" id="btn">
    <div id="content"></div>
    <div id="contentTwo"></div>
    <script>
        window.onscroll = function () {
            var cont = document.getElementById('content');
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

            startMove(document.documentElement.clientHeight - cont.offsetHeight + scrollTop);
        }
        var timer
        function startMove(target) {
            var cont = document.getElementById('content');
            clearInterval(timer);
            timer = setInterval(function () {
                var speed = (target - cont.offsetTop) / 5;
                speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
                if (cont.offsetTop == target) {
                    clearInterval(timer);
                } else {
                    cont.style.top = cont.offsetTop + speed + 'px';
                }

            }, 20)

        }

    </script>
</body>

</html>
 